package com.egu.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.CustomerSource;
import com.egu.service.CustomerSourceService;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("customerSource")
public class CustomerSourceController {

	@Autowired
	private CustomerSourceService customerSourceService;

	@RequestMapping("listUI")
	public String listUI() {
		return "customerSource/listUI";
	}

	// rder = "asc" offset = 0 limit = 10;
	@RequestMapping("/getList")
	@ResponseBody
	public RequestPageVo<CustomerSource> getList(@ModelAttribute(value = "param") PageParam param, CustomerSource customerSource) {
		RequestPageVo<CustomerSource> vo = customerSourceService.getList(param, customerSource);
		return vo;
	}
	
	@RequestMapping("/getAllList")
	@ResponseBody
	public RequestResultVo<List<CustomerSource>> getList() {
		RequestResultVo<List<CustomerSource>> vo = customerSourceService.getAllList();
		return vo;
	}


	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public RequestResultVo<CustomerSource> saveOrUpdate(CustomerSource customerSource) {
		RequestResultVo<CustomerSource> result = new RequestResultVo<CustomerSource>();
		if (customerSource != null) {
			return customerSourceService.saveOrUpdate(customerSource);
		} else {
			result.setSuccess(false);
		}
		return result;
	}
	
	@RequestMapping("/deleteDataById")
	public @ResponseBody RequestResultVo<CustomerSource> deleteDataById(
			@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<CustomerSource> result = new RequestResultVo<CustomerSource>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("传入id为空");
			return result;
		}
		result = customerSourceService.deleteDataById(id);
		return result;
	}
}
